var BaseScene = require('./../../../FrameWork/BaseScene');
var UtilGameObject = require('./../../../FrameWork/Utils/UtilGameObject');
var RollBgCtr = require('./../../../FrameWork/Component/Roll/RollBgCtr');
var EnemysCtr = require('./EnemysCtr');
var MoneyCtr = require('./MoneyCtr');
var ActsCtr = require('./ScqmActsCtr');
var EmitsCtr = require('./ScqmEmitsCtr');
cc.Class(
{
    extends: BaseScene,

    properties:
    {
        prefabRollBg:
        {
            default: null,
            type: cc.Prefab,
            displayName: '滚动预设'
        },
        nodeBg:
        {
            default: null,
            type: cc.Node,
            displayName: '背景节点'
        },
        spriteFrameBg:
        {
            default: null,
            type: cc.SpriteFrame,
            displayName: '背景'
        },
        RollBgList: [RollBgCtr],

        prefabPlane:
        {
            default: null,
            type: cc.Prefab,
            displayName: '飞机预设'
        },
        enemysCtr:
        {
            default: null,
            type: EnemysCtr,
            displayName: '敌机控制器'
        },

        bgMusic:
        {
            default: null,
            type: cc.AudioClip,
            displayName: '背景音乐'
        },
        moneyCtr:
        {
            default: null,
            type: MoneyCtr,
            displayName: '道具管理对象'
        },
        actsCtr:
        {
            default: null,
            type: ActsCtr,
            displayName: '所有物体动作管理类'
        },
        emitsCtr:
        {
            default: null,
            type: EmitsCtr,
            displayName: '发射器管理类'
        }
    },
    onLoad()
    {
        cc.director.getCollisionManager().enabled = true;

        // cc.director.getCollisionManager().enabledDebugDraw = true;

        // cc.director.getCollisionManager().enabledDrawBoundingBox = true;

        this.rollBgCtr = UtilGameObject.getCtrByPrefabs(this.prefabRollBg, this.nodeBg);
        this.rollBgCtr.refreshBgSprite(this.spriteFrameBg);
        this.rollBgCtr.refreshSpeedTo(20, 20);

        this.planeCtr = UtilGameObject.getCtrByPrefabs(this.prefabPlane, this.nodeBg, "BaseMyPlane");
        this.planeCtr.setPositionY(-cc.winSize.height * 0.5);


        this.planeCtr.node.on('eatProp', function(_enumProp, _cnt)
        {
            this.moneyCtr.addPropCnt(_enumProp, _cnt);
        }.bind(this));


        this.planeCtr.on('die', function()
        {
            this.stopAllAction();
        }.bind(this));

        if (!!this.bgMusic)
        {
            cc.audioEngine.playMusic(this.bgMusic, true);
        }
    },

    /***暂停战斗中的所有动作 */
    stopAllAction()
    {
        this.actsCtr.stopAllActions();
        this.emitsCtr.stopAllActions();
    }
});
